<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入vue开发环境版本 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="root">
        <select name="public-choice" v-model="couponSelected" @change="getCouponSelected($event)">
            <option :value="coupon.id" v-for="coupon in couponList">{{coupon.name}}</option>
        </select>
    </div>

    <script type="text/javascript">
        Vue.config.productionTip = false; //阻止vue在启动时产生生产环境提示

        new Vue({
            el: '#root',
            data: {
                couponList: [
                    {
                        id: 'A',
                        name: '优惠券1'
                    },
                    {
                        id: '1',
                        name: '优惠券2'
                    },
                    {
                        id: '2',
                        name: '优惠券3'
                    }
                ],
                newId:'',

                couponSelected: '',
            },
            created() {
                //如果没有这句代码，select中初始化会是空白的，默认选中就无法实现
                //默认显示优惠券3
                for(let i =0;i<this.couponList.length;i++){
                    console.log(this.couponList[i]);
                    if(this.couponList[i].id='1'){
                        this.newId =  this.couponList[i].id 
                    }
                }
                console.log( this.newId);
                this.couponSelected = this.couponList[this.newId].id;
            },
            methods: {
                getCouponSelected(e) {
                    console.log(e.target.value);
                    //获取选中的优惠券
                    console.log(this.couponSelected)
                }

            }
        })
    </script>
</body>

</html>